package com.example.member

import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.member.adapter.MemberAdapter
import com.example.member.databinding.ActivityMemberBinding
import com.example.member.vm.MemShipViewModel
import com.example.member.vm.MemUpViewModel
import com.example.member.vm.MemViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/member/MemberActivity")
class MemberActivity : BaseMvvmActivity<ActivityMemberBinding>() {
    override fun getLayoutId(): Int=R.layout.activity_member
    val memViewModel:MemViewModel by viewModels ()
    val memShipViewModel:MemShipViewModel by viewModels()
    override fun initView() {
        super.initView()
        memViewModel.mSuccessLiveData.observe(this){
            mDataBinding.textView7.text=it.membershipLevel
        }
        mDataBinding.btnUpMember.setOnClickListener {
            if (mDataBinding.textView7.text=="黄金会员") {
                memViewModel.getMemberUp("铂金会员",1119)
                mDataBinding.textView7.text="铂金会员"
            }else  if (mDataBinding.textView7.text=="铂金会员") {
                memViewModel.getMemberUp("钻石会员",1119)
                mDataBinding.textView7.text="钻石会员"
            }else  if (mDataBinding.textView7.text=="钻石会员") {
                ToastUtils.showLong("已经是最高等级会员")
            }
            memViewModel.mSuccessLiveData.observe(this){
                ToastUtils.showLong("升级成功")
            }
        }
        mDataBinding.rg.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.rb1->{
                    mDataBinding.rb1.isChecked=true
                    mDataBinding.rb2.isChecked=false
                    mDataBinding.rb3.isChecked=false
                }
                R.id.rb2->{
                    mDataBinding.rb1.isChecked=false
                    mDataBinding.rb2.isChecked=true
                    mDataBinding.rb3.isChecked=false
                }
                R.id.rb3->{
                    mDataBinding.rb1.isChecked=false
                    mDataBinding.rb2.isChecked=false
                    mDataBinding.rb3.isChecked=true
                }
            }
            if (mDataBinding.rb1.isChecked){
                memShipViewModel.getMemberShip(58)
            }else if (mDataBinding.rb2.isChecked){
                memShipViewModel.getMemberShip(59)
            }else{
                memShipViewModel.getMemberShip(60)
            }
        }
        memShipViewModel.getMemberShip(58)
        memShipViewModel.mSuccessLiveData.observe(this){
            mDataBinding.tv1.text="商家"+it.merchantDiscount+"折"
            mDataBinding.tv2.text=""+it.pointsToCash+"积分可抵1元"
            mDataBinding.tv3.text=""+it.parkingCoupons+"元停车券"
        }
    }

    override fun onResume() {
        super.onResume()
        memViewModel.getMember(1119)
    }

}